Adding some more judges, here and there.
[andmenj-acm.git] / COCI / 2009-2010 / Contest #7 - 24.04.2010 / kraljevi / kraljevi.cpp
bloba759765bfe6e5b9218b4e8e71827797eac453296
1 #include <iostream>
2 #include <algorithm>
3 #include <vector>
4 #include <cassert>
6 #define D(x) cout << #x " = " << (x) << endl
7 using namespace std;
9 const int MAXN = 1005;
10 char mat[MAXN][MAXN];
11 typedef pair<int, int> point;
13 int dist(int x1, int y1, int x2, int y2){
14 int dx = abs(x1 - x2);
15 int dy = abs(y1 - y2);
16 return max(dx, dy);
18 int sum(const vector<point> &p){
19 int n = p.size(), ans = 0;
20 for (int i = 0; i < n; ++i){
21 for (int j = i + 1; j < n; ++j){
22 ans += dist(p[i].first, p[i].second, p[j].first, p[j].second);
25 return ans;
28 int main(){
29 int rows, cols;
30 cin >> rows >> cols;
32 vector<point> a, b;
33 for (int i = 0; i < rows; ++i){
34 for (int j = 0; j < cols; ++j){
35 cin >> mat[i][j];
36 if (mat[i][j] == 'M') a.push_back(point(i, j));
37 if (mat[i][j] == 'S') b.push_back(point(i, j));
41 cout << sum(a) << " " << sum(b) << endl;
42 return 0;